package com.sgb.kjwl.viewmodel.self.driver;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.self.MotorcadeSimpleEntity;
import com.sgb.kjwl.model.entity.self.ProDriverDetailsEntity;
import com.sgb.kjwl.model.response.ListResponse2;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.dialog.DialogHelper;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/10/11
 */
public class ProDriverDetailsModel extends BaseViewModel {

    public MutableLiveData<ProDriverDetailsEntity> detailsLD = new MutableLiveData<>();
    public MutableLiveData<List<MotorcadeSimpleEntity>> motorcadeListLD = new MutableLiveData<>();
    public MutableLiveData<Boolean> deleteLD = new MutableLiveData<>();
    public MutableLiveData<Boolean> unbindLD = new MutableLiveData<>();

    public ProDriverDetailsModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /**
     * 获取司机详情
     *
     * @param context
     * @param no      司机no
     */
    public void getDetails(Context context, String no) {
        DialogHelper.showProgressDialog(context, "数据加载中...");
        NewAPIManager.getInstance().getLogisticsAPI().getProDriverDetails(no).enqueue(new ICallBack<BaseEntity<ProDriverDetailsEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ProDriverDetailsEntity> data) {
                detailsLD.postValue(data.getData());
            }
        });

    }

    /**
     * 请求所有的自营车队列表
     */
    public void requestMotorcadeList(Context context) {
        DialogHelper.showProgressDialog(context, "请求中...");
        Map<String, Object> map = new HashMap<>();
//        map.put("linkState", 3);//挂靠状态 0 全部 1 邀请中 2 已拒绝 3 已同意 4 已解除
        map.put("type", 1);//合作类型 1 自营 2 挂靠
        map.put("page", 1);
        map.put("limit", 99);
        NewAPIManager.getInstance().getLogisticsAPI().getMotorcadeList(map).enqueue(new ICallBack<BaseEntity<ListResponse2<List<MotorcadeSimpleEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse2<List<MotorcadeSimpleEntity>>> data) {
                if (data != null) {
                    if (data.getData() != null) {
                        motorcadeListLD.postValue(data.getData().getList());
                    } else {
                        motorcadeListLD.postValue(null);
                    }
                }
            }
        });
    }

    /**
     * 删除自营司机
     *
     * @param no 司机no
     */
    public void deleteDriver(String no) {
        NewAPIManager.getInstance().getLogisticsAPI().deleteProDriver(no).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                deleteLD.postValue(true);
            }
        });
    }

    /**
     * 删除自营司机
     *
     * @param no 司机no
     */
    public void unbindDriver(String no) {
        NewAPIManager.getInstance().getLogisticsAPI().unbindProDriver(no).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                unbindLD.postValue(true);
            }
        });
    }


}
